import {takeEvery,put,call,delay,all} from 'redux-saga/effects'
// import { delay } from 'redux-saga'
import {INCREMENT_ASYNC,FETCH_USER} from '../constants/counter'
import axios from 'axios';


// const delay = (ms)=> new Promise(resolve =>setTimeout(resolve,ms))

function* incrementAsync(){
 yield delay(2000)
 yield put({type:'INCREMENT'})
}

function* getuser(){
    // const user = yield axios.get('https://jsonplaceholder.typicode.com/users')
    const user = yield call(axios.get,'https://jsonplaceholder.typicode.com/users')
    console.log(user)
   }

 function* watchincrementAsync(){
    yield takeEvery(INCREMENT_ASYNC,incrementAsync)
}


//给FETCH_USER绑定了getuser方法
 function* watchfetchuser(){
    yield takeEvery(FETCH_USER,getuser)
}


//根方法利用all 多并发
export default function* rootSaga(){
    yield all([
        watchincrementAsync(),
        watchfetchuser()
    ])
 

}